package com.example.clock.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.clock.entity.AttendHistory;
import com.example.clock.entity.AttendVo;
import com.example.clock.service.AttendHistoryService;
import com.example.clock.service.AttendService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.text.ParseException;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

@Controller
@RequestMapping("/attendHistory")
public class AttendHistoryController {

    private static final Logger logger = LoggerFactory.getLogger(AttendHistoryController.class);

    @Autowired
    private AttendHistoryService attendHistoryService;

    //上下班打卡
    @GetMapping("/list")
    @ResponseBody
    public List<AttendHistory> clock(String userName,  Integer year,Integer month,Integer day) throws UnsupportedEncodingException {
        LocalDate date = LocalDate.of(year, month, day);
        List<AttendHistory> attendHistoryList = attendHistoryService.list(
                new LambdaQueryWrapper<AttendHistory>()
                        .eq(AttendHistory::getName, userName)
                        .eq(AttendHistory::getCurrentDateTime, date)
        );
        return attendHistoryList;
    }


}
